package com.softWang.job.controller;

import com.softWang.common.aop.annotation.SysOperationLog;
import com.softWang.job.constants.SysModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

import com.softWang.common.response.PageBean;
import com.softWang.common.request.Idparam;
import com.softWang.common.response.ResponseResult;
import com.softWang.job.po.JobLog;
import com.softWang.job.service.JobLogService;
import com.softWang.job.vo.jobLog.*;

@Api(value="定时任务执行日志",tags="定时任务执行日志")
@Validated
@RestController
@RequestMapping("/job/jobLog")
public class JobLogController {
     @Resource
     private JobLogService jobLogService;

     @PreAuthorize("@ss.hasPermi('job:log:query')")
     @ApiOperation(value="列表(分页)")
     @RequestMapping(value = "/query", method = RequestMethod.POST)
     public ResponseResult<PageBean<JobLogQueryAllResult>> queryall(@RequestBody @Validated JobLogQueryAllParam param, HttpServletRequest request) {
         List<JobLogQueryAllResult> results=jobLogService.queryall(param);
         PageBean page=new PageBean(results);
         return ResponseResult.success(page);
     }

     @PreAuthorize("@ss.hasPermi('job:log:detail')")
     @ApiOperation(value="查看详情")
     @RequestMapping(value = "/detail", method = RequestMethod.POST)
     public ResponseResult<JobLogDetailResult> detail(@RequestBody @Validated Idparam idparam) {
         JobLogDetailResult result = new JobLogDetailResult();
         JobLog entity = jobLogService.getById(idparam.getId());
         BeanUtils.copyProperties(entity, result);
         return ResponseResult.success(result);
     }

     @PreAuthorize("@ss.hasPermi('job:log:del')")
     @ApiOperation(value="删除定时任务执行日志")
     @SysOperationLog(value = "删除定时任务执行日志", model = SysModel.JOB_LOG)
     @RequestMapping(value = "/del", method = RequestMethod.POST)
     public ResponseResult del(@RequestBody @NotEmpty(message = "ids 不能为空") List<@NotNull(message = "ids 不能为空") Long> ids, HttpServletRequest request) {
         jobLogService.del(ids);
         return ResponseResult.success();
     }


    @PreAuthorize("@ss.hasPermi('job:log:clean')")
    @SysOperationLog(value = "清空定时任务执行日志", model = SysModel.JOB_LOG)
    @PostMapping("/clean")
    public ResponseResult clean()
    {
        jobLogService.cleanJobLog();
        return ResponseResult.success();
    }
}